from config import HOST
from utils import GetLog
log = GetLog.get_logger()


class ApiApproveTrust:

    def __init__(self, session):
        self.session = session
        self.__url_approve = HOST + '/member/realname/approverealname'
        self.__url_approve_status = HOST + '/member/member/getapprove'
        self.__url_trust = HOST + '/trust/trust/register'
        self.__url_img_code = HOST + '/common/public/verifycode1/{}'
        self.__url_recharge = HOST + '/trust/trust/recharge'

    # 认证接口
    def api_approve(self):
        data = {
            "realname": "张三",
            "card_id": "110101198001010110"
        }
        log.info('正在调用认证接口，请求方法：{}, 请求url: {}, 请求参数：{}'.format("post", self.__url_approve, data))
        return self.session.post(url=self.__url_approve, data=data, files={"x": "y"})

    # 查询认证状态接口
    def api_approve_status(self):
        log.info('正在调用查询认证状态接口，请求方法：{}, 请求url: {}'.format("post", self.__url_approve_status))

        return self.session.post(url=self.__url_approve_status)

    # 开户接口
    def api_trust(self):
        log.info('正在调用开户接口，请求方法：{}, 请求url: {}'.format("post", self.__url_trust))
        return self.session.post(url=self.__url_trust)

    # 获取图片验证码接口
    def api_img_code(self, random):
        log.info('正在调用获取图片验证码接口，请求方法：{}, 请求url: {}'.format("get", self.__url_img_code.format(random)))
        return self.session.get(url=self.__url_img_code.format(random))

    # 充值接口
    def api_recharge(self, valicode):
        data = {
            "paymentType": "chinapnrTrust",
            "amount": "1000",
            "formStr": "reForm",
            "valicode": valicode
        }
        log.info('正在调用充值接口，请求方法：{}, 请求url: {}, 请求参数：{}'.format("post", self.__url_recharge, data))
        return self.session.post(url=self.__url_recharge, data=data)